from typing import List


class Solution:
    def firstMissingPositive(self, nums: List[int]) -> int:
        # 复杂度 log(n) 符合题目要求
        nums.sort()

        n=len(nums)
        cur=1
        for i in range(n):
            # 去重
            if i>=1 and nums[i]==nums[i-1]:
                continue
            if nums[i]>0 and cur!=nums[i]:
                return cur
            if cur==nums[i]:
                cur+=1
        return cur
